<template>
	<div ref="local">
		<module-balance class="module_panel" />
		<van-cell-group class="module_panel">
			<van-cell icon="sign" title="我的银行卡" to="/user/bank" isLink />
		</van-cell-group>
		<!-- 是团长才具有的 -->
		<div v-if="isTeam" class="isclude">
			<module-commission class="module_panel" />
			<!-- 单品排行 -->
			<user-sale-sort :sortObject="soloOrderList" :title="soloTitle" v-if="this.soloOrderList"/>
			<!-- 分类排行 -->
			<user-sale-sort :sortObject="cateOrderList" :title="cateTitle" v-if="this.cateOrderList"/>
			<van-cell-group class="module_panel">
				<van-cell icon="records" title="售后工单" :to="'/user/shop-work-list/' + teamId" isLink />
				<van-cell icon="records" title="门店订单" :to="'/user/shop-order-list/' + teamId" isLink />
				<van-cell icon="exchange" title="合作团长" to="/user/team" isLink />
				<van-cell icon="contact" title="旗下会员" to="/user/member" isLink />
       			<van-cell icon="chat" title="到货提醒" to="/user/remind" isLink />
			</van-cell-group>

			<van-cell-group class="module_panel">
				<van-cell icon="gold-coin" title="提成统计" to="/user/commission/sum" isLink />
				<van-cell icon="idcard" title="门店排行" to="/user/shop-ranking" isLink />
				<van-cell icon="info-o" title="门店统计" to="/user/shop-statistic" isLink />
			</van-cell-group>

			<van-cell-group class="module_panel">
				<van-cell icon="edit-data" title="代客下单" @click="toAssistBuy()" isLink><span class="red">{{assistMode ? '取消代客模式' : ''}}</span></van-cell>
				<van-cell icon="pending-orders" title="送货清单" to="/user/pickup" isLink />
			</van-cell-group>
			<!-- 清分 -->
			<!-- <van-cell-group class="module_panel">
				<van-cell icon="gold-coin" title="清分" to="/user/clean" isLink />
			</van-cell-group> -->
		</div>
		<van-cell-group v-if="user.isSupplier" class="module_panel">
			<van-cell icon="points-mall" title="供应商中心" to="/user/supply" isLink />
		</van-cell-group>
	</div>
</template>

<script>
	import ModuleTask from "./module-task";
	import ModuleBalance from "./module-balance";
	import ModuleCommission from "./module-commission";
	import { ASSIST_MODE } from "@/api/global";
	import {SHOP_APPOINT} from "@/api/user"
	import UserSaleSort from "@/vue/components/user-sale-sort"

	export default {
		name: "user-module",
		props: {

		},
		data() {
			const user = this.getUser();
			return {
				memberId: this.getUser().id,
				centreId: this.getUser().centreId,
				soloTitle:"单品销售排行",
				cateTitle:"分类销售排行",
				soloOrderList:{},
				cateOrderList:{},
				teamId: user.id,
				assistMode: false
			}
		},
		computed: {
			isTeam() {
				return (this.user.isteam === 3);
			}
		},
		created() {
			this.user = this.getUser();
			this.assistMode = this.isAssistMode();
			this.getSoloCate();
		},
		methods: {
		//获取单品和分类的排名
		getSoloCate(){
			this.$reqPost(SHOP_APPOINT,{centerId: this.centreId,memberId:this.memberId }).then(res=>{
				if (res.status == 200) {
					this.soloOrderList = res.data.data.productSale;
					this.cateOrderList = res.data.data.categorySale;
				}
			})
		},
		toAssistBuy() {
			if (this.assistMode) {
				this.assistMode = false;
				this.setAssistMode(false);
			} else {
				this.setAssistMode(true);
				this.$router.push({name: 'home'});
				}
			}
		},

		components: {
			[ModuleTask.name]: ModuleTask,
			[ModuleBalance.name]: ModuleBalance,
			[ModuleCommission.name]: ModuleCommission,
			[UserSaleSort.name]: UserSaleSort
		}
	}
</script>

<style scoped lang="scss">
	.module_panel {
		margin-bottom: 10px;
	}

</style>
